package cc.rengu.igas.opms.core.service.trans.common;

import cc.rengu.igas.opms.common.constant.OpmsTreeNodeConstant;
import cc.rengu.igas.opms.common.constant.OpmsParamConstant;
import cc.rengu.igas.opms.common.enums.RespCodeEnum;
import cc.rengu.igas.opms.core.service.base.ManageService;
import cc.rengu.igas.opms.facade.bean.OrderInfoBean;
import cc.rengu.igas.opms.facade.bean.PayAcctInfoBean;
import cc.rengu.igas.opms.facade.request.PayOrderStatusQueryRequest;
import cc.rengu.igas.opms.facade.response.PayOrderStatusQueryResponse;
import cc.rengu.igas.share.common.constant.ShareParamConstant;
import cc.rengu.igas.share.common.constant.TransCacheConstant;
import cc.rengu.igas.share.common.constant.UserSessionConstant;
import cc.rengu.igas.share.core.model.MchntInfo;
import cc.rengu.igas.share.core.model.PlatMchntInfo;
import cc.rengu.igas.share.core.model.UserInfo;
import cc.rengu.igas.share.core.realize.MchntService;
import cc.rengu.igas.share.core.realize.UserService;
import cc.rengu.igas.share.core.realize.impl.MchntServiceImpl;
import cc.rengu.igas.share.core.realize.impl.UserServiceImpl;
import cc.rengu.oltp.service.base.ChannelBaseService;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.service.common.dao.MchntOrderDetailMapper;
import cc.rengu.oltp.service.common.dao.MchntOrderInfoMapper;
import cc.rengu.oltp.service.common.dao.PayOrderInfoMapper;
import cc.rengu.oltp.service.common.dao.UserOrderInfoMapper;
import cc.rengu.oltp.service.common.dao.impl.MchntOrderDetailMapperImpl;
import cc.rengu.oltp.service.common.dao.impl.MchntOrderInfoMapperImpl;
import cc.rengu.oltp.service.common.dao.impl.PayOrderInfoMapperImpl;
import cc.rengu.oltp.service.common.dao.impl.UserOrderInfoMapperImpl;
import cc.rengu.oltp.service.common.entity.*;
import cc.rengu.oltp.service.common.enums.*;
import cc.rengu.oltp.service.model.BizException;
import cc.rengu.oltp.service.model.BizResponse;
import cc.rengu.oltp.service.model.OrderInfo;
import cc.rengu.oltp.service.realize.OrderService;
import cc.rengu.oltp.service.realize.SysParamService;
import cc.rengu.oltp.service.realize.TransCustomImpl;
import cc.rengu.oltp.service.realize.impl.OrderServiceImpl;
import cc.rengu.oltp.service.realize.impl.SysParamServiceImpl;
import cc.rengu.oltp.utility.util.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;


import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
 * 订单状态查询
 * Created by fyp on 2020/4/14.
 * modify by wangcheng on 2021-09-13
 */
public class PayOrderStatusQueryEntranceService extends ManageService implements TransCustomImpl {

    @Override
    protected Object bizBeforeCust() throws Exception {
        PayOrderStatusQueryRequest payOrderStatusQueryRequest = new PayOrderStatusQueryRequest();
        ConvertUtil.convertOutput(payOrderStatusQueryRequest);
        return payOrderStatusQueryRequest;
    }

    @Override
    protected BizResponse bizProcessCust(Object request) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        PayOrderStatusQueryRequest payOrderStatusQueryRequest = (PayOrderStatusQueryRequest) request;
        PayOrderStatusQueryResponse payOrderStatusQueryResponse = new PayOrderStatusQueryResponse();
        BizResponse bizResponse = new BizResponse();
        bizResponse.setRspSysId(AppParamConstant.IGAS);
        payOrderStatusQueryResponse.setHeader(payOrderStatusQueryRequest.getHeader());
        String instId = payOrderStatusQueryRequest.getHeader().getInstId();
        UserService userService = new UserServiceImpl();
        /* 根据用户订单号查询交易 */
        OrderService orderService = new OrderServiceImpl();
        UserOrderInfoMapper userOrderInfoMapper = new UserOrderInfoMapperImpl();
        UserOrderInfo userOrderInfo = userOrderInfoMapper.selectUserOrderInfoByUserOrderId(instId, payOrderStatusQueryRequest.getUserOrderId());
        if (userOrderInfo == null) {
            rglog.error("用户支付订单不存在");
            throw new BizException(RespCodeEnum.ORDER_NOEXIT.getRespCode(), RespCodeEnum.ORDER_NOEXIT.getRespDesc());
        }
        GlobalTransUtil.setCacheValue(TransCacheConstant.USER_ORDER_INFO, userOrderInfo);
        rglog.debug("前端交易查询开始，原交易系统流水号<{}>", userOrderInfo.getSysSeqNum());
        xmlTreeUtil.setXmlTreeStringValue(OpmsTreeNodeConstant.FRONT_BACK_URL, userOrderInfo.getFrontBackUrl());

        /*判断上传用户与用户订单表中的用户是否是同一个用户*/
        if (!StringUtil.isEmptyOrNull(payOrderStatusQueryRequest.getUserId())
                && !StringUtil.isEmptyOrNull(userOrderInfo.getUserId())
                && !payOrderStatusQueryRequest.getUserId().equals(userOrderInfo.getUserId())) {
            rglog.error("上送的用户:<{}>与用户订单表中用户信息不一致:<{}>", payOrderStatusQueryRequest.getUserId(), userOrderInfo.getUserId());
            throw new BizException(RespCodeEnum.USER_INFO_MISMATCH.getRespCode(), RespCodeEnum.USER_INFO_MISMATCH.getRespDesc());
        }

        /*校验商户号与用户订单号是否匹配*/
        if (!StringUtil.isEmptyOrNull(payOrderStatusQueryRequest.getPlatMchntNo()) &&
                !payOrderStatusQueryRequest.getPlatMchntNo().equals(userOrderInfo.getGroupMchntNo())) {
            rglog.error("支付交易校验上传的平台商户号:<{}>与用户订单表中的平台商户号:<{}>不一致",
                    payOrderStatusQueryRequest.getPlatMchntNo(), userOrderInfo.getGroupMchntNo());
            throw new BizException(RespCodeEnum.ORDER_NOEXIT.getRespCode(), RespCodeEnum.ORDER_NOEXIT.getRespDesc());
        }

        if (BizStatusEnum.INIT.getStatus().equals(userOrderInfo.getBizStatus()) &&
                OrderStatusEnum.INIT.getStatus().equals(userOrderInfo.getOrderStatus()) &&
                TransStatusEnum.TRANS_INIT.getStatus().equals(userOrderInfo.getTransStatus())){
            rglog.debug("订单还是初始状态,用户还未支付,直接返回结果为处理中!");
            OrderInfoBean orderInfoBean = new OrderInfoBean();
            BeanUtil.beanCopy(userOrderInfo, orderInfoBean);
            orderInfoBean.setTransDate(userOrderInfo.getTxnDate());
            orderInfoBean.setTransTime(userOrderInfo.getTxnTime());
            payOrderStatusQueryResponse.setOrderInfo(orderInfoBean);
            payOrderStatusQueryResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
            payOrderStatusQueryResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());
            bizResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
            bizResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());
            bizResponse.setResult(payOrderStatusQueryResponse);
            return bizResponse;
        }

        /*查询商户支付订单列表*/
        MchntOrderInfoMapper mchntOrderInfoMapper = new MchntOrderInfoMapperImpl();
        List<MchntOrderInfo> mchntOrderInfoList = mchntOrderInfoMapper.selectMchntOrderInfoBySysSeqNum(instId, userOrderInfo.getSysSeqNum());
        if (null == mchntOrderInfoList || mchntOrderInfoList.isEmpty()) {
            rglog.error("订单信息表中无该笔商户支付订单,instId:<{}>,sysSeqNum:<{}>.", instId, userOrderInfo.getSysSeqNum());
            /*更新订单表状态为失败*/
            userOrderInfo.setTransStatus(TransStatusEnum.SYSTEM_REJECT.getStatus());
            userOrderInfo.setBizStatus(BizStatusEnum.FINISH.getStatus());
            userOrderInfo.setUpdateTime(DateUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS"));
            if (!orderService.updateOrderInfo(userOrderInfo, null, null)) {
                rglog.error("更新订单表状态失败");
            }
            throw new BizException(RespCodeEnum.ORDER_NOEXIT.getRespCode(), RespCodeEnum.ORDER_NOEXIT.getRespDesc());
        }
        GlobalTransUtil.setCacheValue(TransCacheConstant.MCHNT_ORDER_INFO_LIST, mchntOrderInfoList);

        /*无跳转首次签约并支付的交易返回userId,userId放到内部节点中用于放回给前端*/
        if ("P01PM013".equals(mchntOrderInfoList.get(0).getTxnNum())) {
            rglog.debug("无跳转首次签约并支付的交易返回userId:<{}>", userOrderInfo.getUserId());
            xmlTreeUtil.setXmlTreeStringValue(OpmsTreeNodeConstant.USER_ID, userOrderInfo.getUserId());
        }

        /*获取支付订单列表*/
        PayOrderInfoMapper payOrderInfoMapper = new PayOrderInfoMapperImpl();
        List<PayOrderInfo> payOrderInfoList = payOrderInfoMapper.selectPayOrderInfoBySysSeqNum(instId, userOrderInfo.getSysSeqNum());
        /* 过滤实时入账的支付订单 */
        Predicate<PayOrderInfo> d0Filter1 = p -> !ShareParamConstant.SUB_SYS_ID_D0_REALTIME.equals(p.getChannelBizType());
        Predicate<PayOrderInfo> d0Filter2 = p -> !ShareParamConstant.OTHER_SUB_SYS_ID_D0_REALTIME.equals(p.getChannelBizType());
        payOrderInfoList = payOrderInfoList.stream().filter(d0Filter1.and(d0Filter2))
                .sorted(Comparator.comparing(PayOrderInfo::getDstCallIndex)).collect(Collectors.toList());
        /* 获取主体支付方 */
        Predicate<PayOrderInfo> acctFilter = p -> !ChannelEnum.ACCT.getChannelType().equals(p.getMsgDstId());
        Predicate<PayOrderInfo> mompFilter = p -> !ChannelEnum.MOMP.getChannelType().equals(p.getMsgDstId());
        List<PayOrderInfo> payOrderInfoListFilter = payOrderInfoList.stream().filter(acctFilter.and(mompFilter)).collect(Collectors.toList());
        /* 判断是否为混合支付场景,若为混合支付时，也只会是主支付方式状态不明，故过滤掉非主支付方式的记录  */
        Predicate<PayOrderInfo> scoreFilter = p -> PayTypeEnum.SCORE.getPayType().equals(p.getPayType());
        if (payOrderInfoListFilter.stream().filter(scoreFilter).anyMatch(scoreFilter)) {
            Predicate<PayOrderInfo> mixScoreFilter = p -> !PayTypeEnum.SCORE.getPayType().equals(p.getPayType());
            payOrderInfoListFilter = payOrderInfoListFilter.stream().filter(mixScoreFilter).collect(Collectors.toList());
            GlobalTransUtil.setCacheValue(TransCacheConstant.MIX_PAY_FLAG, AppParamConstant.YES);
        }
        if (payOrderInfoListFilter.isEmpty()) {
            rglog.debug("根据机构号<{}>、系统流水号<{}>未找到支付订单信息,直接更交易状态为失败!", instId, userOrderInfo.getSysSeqNum());
            updateOrderFail(userOrderInfo, mchntOrderInfoList);
            /* 生成动态码后未有app扫码支付，不存在支付订单表流水 */
            OrderInfoBean orderInfoBean = new OrderInfoBean();
            BeanUtil.beanCopy(userOrderInfo, orderInfoBean);
            orderInfoBean.setTransDate(userOrderInfo.getTxnDate());
            orderInfoBean.setTransTime(userOrderInfo.getTxnTime());
            payOrderStatusQueryResponse.setOrderInfo(orderInfoBean);
            payOrderStatusQueryResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
            payOrderStatusQueryResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());
            bizResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
            bizResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());
            bizResponse.setResult(payOrderStatusQueryResponse);
            return bizResponse;
        }
        /* 判断是否存在商户D0实时入账的流水 */
        payOrderInfoListFilter = payOrderInfoListFilter.stream().filter(item -> !"D0".equals(item.getDstChannelType())).collect(Collectors.toList());
        rglog.info("主支付订单数据信息:<{}>", JSON.toJSONString(payOrderInfoListFilter));
        if (payOrderInfoListFilter.size() > 1) {
            rglog.error("当前交易存在多种主支付方式，请排查是否存在主支付方式过滤问题!");
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }
        PayOrderInfo payOrderInfo = payOrderInfoListFilter.get(0);
        GlobalTransUtil.setCacheValue(TransCacheConstant.PAY_ORDER_INFO, payOrderInfo);

        /*判断订单状态是否明确*/
        if (!BizStatusEnum.PROCESSING.getStatus().equals(userOrderInfo.getBizStatus())) {
            rglog.debug("订单业务状态<{}>,非处理中<01>，状态明确直接返回支付订单状态", userOrderInfo.getBizStatus());
            /*初始状态时，判断订单是否过期，过期则更新状态*/
            if (BizStatusEnum.INIT.getStatus().equals(userOrderInfo.getBizStatus()) &&
                    DateUtil.compareTime(DateUtil.getCurrentDateTime("yyyyMMddHHmmss"),
                            userOrderInfo.getOrderExpiryTime(), "yyyyMMddHHmmss") > 0) {
                userOrderInfo.setOrderStatus(OrderStatusEnum.CLOSE.getStatus());
                userOrderInfo.setBizStatus(BizStatusEnum.FAILED.getStatus());
                userOrderInfo.setUpdateTime(DateUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS"));
                /* 更新商户订单表的状态为失败 */
                mchntOrderInfoList.forEach(item -> item.setBizStatus(BizStatusEnum.FAILED.getStatus()));
                if (!orderService.updateOrderInfo(userOrderInfo, mchntOrderInfoList, null)) {
                    rglog.info("更新用户订单表");
                }
            }
            payOrderStatusQueryResponse.setOrderInfo(getOrderInfo(userOrderInfo, mchntOrderInfoList, payOrderInfo));
            payOrderStatusQueryResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
            payOrderStatusQueryResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());
            bizResponse.setRspSysId(AppParamConstant.IGAS);
            bizResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
            bizResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());
            bizResponse.setResult(payOrderStatusQueryResponse);
            if (TransStatusEnum.TRANS_SUCC.getStatus().equals(userOrderInfo.getTransStatus()) &&
                    BizStatusEnum.FINISH.getStatus().equals(userOrderInfo.getBizStatus()) &&
                    ("P01PM011".equals(mchntOrderInfoList.get(0).getTxnNum()) || "P01PM013".equals(mchntOrderInfoList.get(0).getTxnNum()))) {
                rglog.debug("交易成功后在会话中设置userId:<{}>,sessionId:<{}>", userOrderInfo.getUserId(), payOrderStatusQueryRequest.getHeader().getSession());
                if (!StringUtil.isEmptyOrNull(payOrderStatusQueryRequest.getHeader().getSession())) {
                    userService.setUserSessionValue("userId", userOrderInfo.getUserId());
                }
                /*他行卡首次签名并支付返回用户名*/
                String userName = getUserName(payOrderStatusQueryRequest, userOrderInfo.getUserId());
                payOrderStatusQueryResponse.setUserName(userName);
            }
            return bizResponse;
        }

        /* 退款交易状态查询，查询原支付交易订单信息 */
        if (TransTypeEnum.REFUND.equals(TransTypeEnum.getTransType(payOrderInfo.getTxnNum()))) {
            getOrigOrderInfo(instId, userOrderInfo, mchntOrderInfoList);
        }

        /* 调用支付通道查询订单状态 */
        List<ChannelCallCfg> channelCallCfgList = txnInfo.getChannelCallCfgList().stream().filter(item ->
                item.getCallIndex().equals(ChannelBaseService.FIRST_CHANNEL_CALL_INDEX)).collect(Collectors.toList());
        ChannelCallCfg channelCallCfg = channelCallSceneDiscern(payOrderStatusQueryRequest, channelCallCfgList);
        OrderInfo orderInfo = new OrderInfo();
        orderInfo.setUserOrderInfo(userOrderInfo);
        orderInfo.setMchntOrderInfoList(mchntOrderInfoList);
        orderInfo.setPayOrderInfoList(payOrderInfoList);
        Class channelClasz = Class.forName(channelCallCfg.getCallChannelImpl());
        ChannelBaseService channelBaseService = (ChannelBaseService) channelClasz.newInstance();
        channelBaseService.callService(txnInfo, orderInfo, channelCallCfg.getBizScene(), request);
        /* 交易结果信息赋值 */
        if (TransStatusEnum.TRANS_SUCC.getStatus().equals(userOrderInfo.getTransStatus()) &&
                BizStatusEnum.FINISH.getStatus().equals(userOrderInfo.getBizStatus()) &&
                ("P01PM011".equals(mchntOrderInfoList.get(0).getTxnNum()) || "P01PM013".equals(mchntOrderInfoList.get(0).getTxnNum()))) {
            rglog.debug("交易成功后在会话中设置userId:<{}>,sessionId:<{}>", userOrderInfo.getUserId(), payOrderStatusQueryRequest.getHeader().getSession());
            if (!StringUtil.isEmptyOrNull(payOrderStatusQueryRequest.getHeader().getSession())) {
                userService.setUserSessionValue("userId", userOrderInfo.getUserId());
            }
            /*他行卡首次签名并支付返回用户名*/
            String userName = getUserName(payOrderStatusQueryRequest, userOrderInfo.getUserId());
            payOrderStatusQueryResponse.setUserName(userName);
        }
        payOrderStatusQueryResponse.setOrderInfo(getOrderInfo(userOrderInfo, mchntOrderInfoList, payOrderInfo));
        payOrderStatusQueryResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        payOrderStatusQueryResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());
        bizResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        bizResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());
        bizResponse.setResult(payOrderStatusQueryResponse);
        return bizResponse;

    }

    @Override
    protected void bizAfterCust(Object response) throws Exception {
        BizResponse bizResponse = (BizResponse) response;
        PayOrderStatusQueryResponse payOrderStatusQueryResponse = (PayOrderStatusQueryResponse) bizResponse.getResult();
        ConvertUtil.convertInput(payOrderStatusQueryResponse);
    }

    /**
     * 获取响应订单信息
     *
     * @param userOrderInfo      用户订单信息
     * @param mchntOrderInfoList 商户订单信息
     * @param payOrderInfo       支付订单信息
     * @return 接口返回的订单信息
     * @throws Exception 异常
     */
    private OrderInfoBean getOrderInfo(UserOrderInfo userOrderInfo, List<MchntOrderInfo> mchntOrderInfoList, PayOrderInfo payOrderInfo) throws Exception {
        OrderInfoBean orderInfoBean = new OrderInfoBean();
        BeanUtil.beanCopy(userOrderInfo, orderInfoBean);
        orderInfoBean.setDiscountAmt(userOrderInfo.getRealDiscountAmt());
        orderInfoBean.setTransDate(userOrderInfo.getTxnDate());
        orderInfoBean.setTransTime(userOrderInfo.getTxnTime());
        /*获取商户信息*/
        MchntService mchntService = new MchntServiceImpl();
        if (mchntOrderInfoList.size() > 1 || !StringUtil.isEmptyOrNull(userOrderInfo.getGroupMchntNo())) {
            /*合并订单支付 取平台商户信息*/
            PlatMchntInfo platMchntInfo = mchntService.getPlatMchntInfo(userOrderInfo.getInstId(), userOrderInfo.getGroupMchntNo());
            if (null == platMchntInfo) {
                rglog.error("平台商户信息不存在或商户非正式商户");
                throw new BizException(RespCodeEnum.PLATMCHNT_NOT_BLANK.getRespCode(), RespCodeEnum.PLATMCHNT_NOT_BLANK.getRespDesc());
            } else {
                orderInfoBean.setMchntNo(platMchntInfo.getPlatMchntNo());
                orderInfoBean.setMchntName(platMchntInfo.getPlatMchntName());
            }
            /*计算退款总金额*/
            orderInfoBean.setRefundAmt(countRefundAmt(mchntOrderInfoList));
        } else {
            /*非合并订单 取进商户基本信息*/
            MchntInfo mchntInfo = mchntService.getMchntInfo(userOrderInfo.getInstId(), mchntOrderInfoList.get(0).getMchntNo());
            /*获取系统参数判断是否展示商户简称*/
            SysParamService sysParamService = new SysParamServiceImpl();
            SysParam sysParam = sysParamService.getSysParamInfo(userOrderInfo.getInstId(), OpmsParamConstant.OPMS_SYS_PARAM,
                    OpmsParamConstant.SHOWMCHNTSIMPLENAME + mchntOrderInfoList.get(0).getMchntNo());
            if (null == mchntInfo) {
                rglog.error("基本商户不存在或商户非正式商户");
                throw new BizException(RespCodeEnum.PLATMCHNT_NOT_BLANK.getRespCode(), RespCodeEnum.PLATMCHNT_NOT_BLANK.getRespDesc());
            } else if (sysParam != null && OpmsParamConstant.STR_ONE.equals(sysParam.getParamValue()) &&
                    !StringUtil.isEmptyOrNull(mchntInfo.getMchntSimpleName())) {
                orderInfoBean.setMchntNo(mchntInfo.getMchntNo());
                /*商户简称*/
                orderInfoBean.setMchntName(mchntInfo.getMchntSimpleName());
            } else {
                orderInfoBean.setMchntNo(mchntInfo.getMchntNo());
                orderInfoBean.setMchntName(mchntInfo.getMchntName());
            }
            orderInfoBean.setRefundAmt(mchntOrderInfoList.get(0).getRefundAmt());
        }
        if (null != payOrderInfo) {
            PayAcctInfoBean payAcctInfoBean = new PayAcctInfoBean();
            payAcctInfoBean.setPayType(payOrderInfo.getPayType());
            payAcctInfoBean.setTranAmt(payOrderInfo.getRealPayAmt());
            payAcctInfoBean.setPayerAcctInfo(payOrderInfo.getPayerAcctInfo());
            payAcctInfoBean.setPayerAcctType(payOrderInfo.getPayeeAcctType());
            orderInfoBean.setPayAcctInfo(payAcctInfoBean);
        }
        return orderInfoBean;
    }

    /**
     * 更新用户订单及商户订单
     *
     * @param userOrderInfo      用户订单
     * @param mchntOrderInfoList 商户订单
     * @throws Exception 异常
     */
    private void updateOrderFail(UserOrderInfo userOrderInfo, List<MchntOrderInfo> mchntOrderInfoList) throws Exception {
        userOrderInfo.setTransStatus(TransStatusEnum.SYSTEM_REJECT.getStatus());
        userOrderInfo.setBizStatus(BizStatusEnum.FAILED.getStatus());
        userOrderInfo.setUpdateTime(DateUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS"));
        for (MchntOrderInfo mchntOrderInfo : mchntOrderInfoList) {
            mchntOrderInfo.setTransStatus(TransStatusEnum.SYSTEM_REJECT.getStatus());
            mchntOrderInfo.setBizStatus(BizStatusEnum.FAILED.getStatus());
            mchntOrderInfo.setUpdateTime(DateUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS"));
        }
        OrderServiceImpl orderService = new OrderServiceImpl();
        if (!orderService.updateOrderInfo(userOrderInfo, mchntOrderInfoList, null)) {
            rglog.warn("更新订单表状态失败");
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }
    }

    /**
     * 退款交易获取原支付交易商户订单信息，并累计商户退款金额及手续费信息
     *
     * @param instId             多法人标识
     * @param userOrderInfo      退款用户订单信息
     * @param mchntOrderInfoList 退款商户订单信息
     * @throws Exception 异常
     */
    void getOrigOrderInfo(String instId, UserOrderInfo userOrderInfo, List<MchntOrderInfo> mchntOrderInfoList) throws Exception {
        String totalRefundAmt = "0";
        UserOrderInfoMapper userOrderInfoMapper = new UserOrderInfoMapperImpl();
        MchntOrderInfoMapper mchntOrderInfoMapper = new MchntOrderInfoMapperImpl();
        PayOrderInfoMapper payOrderInfoMapper = new PayOrderInfoMapperImpl();
        UserOrderInfo origUserOrderInfo = userOrderInfoMapper.selectUserOrderInfoByPrimaryKey(instId, userOrderInfo.getOrigSysSeqNum());
        List<MchntOrderInfo> origMchntOrderInfoList = mchntOrderInfoMapper.selectMchntOrderInfoBySysSeqNum(instId, userOrderInfo.getOrigSysSeqNum());
        List<PayOrderInfo> origPayOrderInfoList = payOrderInfoMapper.selectPayOrderInfoBySysSeqNum(instId, userOrderInfo.getOrigSysSeqNum());
        if (null == origUserOrderInfo || null == origMchntOrderInfoList || origMchntOrderInfoList.isEmpty() || null == origPayOrderInfoList || origPayOrderInfoList.isEmpty()) {
            rglog.info("用户订单信息表中无该笔订单信息,instId:<{}>,sysSeqNum:<{}>.", instId, userOrderInfo.getOrigSysSeqNum());
            return;
        }
        /* 查询原商户子订单表 */
        MchntOrderDetailMapper mchntOrderDetailMapper = new MchntOrderDetailMapperImpl();
        List<MchntOrderDetail> mchntOrderDetailList = mchntOrderDetailMapper.selectMchntOrderDetailByRefundSeqNum(userOrderInfo.getInstId(), userOrderInfo.getSysSeqNum());
        if (mchntOrderDetailList != null && !mchntOrderDetailList.isEmpty()) {
            for (MchntOrderDetail mchntOrderDetail : mchntOrderDetailList) {
                mchntOrderDetail.setMchntOrderStatus("01");
                mchntOrderDetail.setUpdateTime(DateUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS"));
            }
            GlobalTransUtil.setCacheValue(TransCacheConstant.MCHNT_ORDER_DETAIL_LIST, mchntOrderDetailList);
        }
        /*累计用户退款金额*/
        for (MchntOrderInfo mchntOrderInfo : origMchntOrderInfoList) {
            if (mchntOrderInfo.getRefundAmt() != null) {
                totalRefundAmt = AmountUtil.addition(mchntOrderInfo.getRefundAmt(), totalRefundAmt);
            }
        }
        totalRefundAmt = AmountUtil.addition(userOrderInfo.getOrderAmt(), totalRefundAmt);
        boolean totalRefundFlag = AmountUtil.compare(origUserOrderInfo.getOrderAmt(), totalRefundAmt) == 0;
        /* 根据是否担保支付和原支付交易中用户订单的业务状态判断设置原用户订单的业务状态 */
        if ("01".equals(origMchntOrderInfoList.get(0).getBizSceneType())) {
            rglog.debug("原订单为担保支付,根据用户订单业务状态:<{}>判断是已确认退款还是未确认收货的退款", origUserOrderInfo.getBizStatus());
            if (BizStatusEnum.CONFIRM.getStatus().equals(origUserOrderInfo.getBizStatus())
                    || BizStatusEnum.PART_REFUND.getStatus().equals(origUserOrderInfo.getBizStatus())) {
                origUserOrderInfo.setBizStatus(totalRefundFlag ? BizStatusEnum.REFUND.getStatus() : BizStatusEnum.PART_REFUND.getStatus());
            } else {
                origUserOrderInfo.setBizStatus(totalRefundFlag ? BizStatusEnum.NOT_CONFIRM_REFUND.getStatus() : BizStatusEnum.NOT_CONFIRM_PART_REFUND.getStatus());
                /* 记录当前订单是否是未确认收货的担保支付订单，在预授权完成处理逻辑中进行退款推送消息时判断若是未确认收货的退款订单就不推送消息并且不记预授权完成 */
                GlobalTransUtil.setCacheValue(TransCacheConstant.ORDER_COMFIRM_FLAG, AppParamConstant.NO);
            }
        } else {
            origUserOrderInfo.setBizStatus(totalRefundFlag ? BizStatusEnum.REFUND.getStatus() : BizStatusEnum.PART_REFUND.getStatus());
        }
        /* 设置商户的累积退款金额、累积退款手续费 */
        for (MchntOrderInfo mchntOrderInfoRefund : mchntOrderInfoList) {
            List<MchntOrderInfo> mchntOrderInfos = origMchntOrderInfoList.stream().filter(item -> item.getMchntNo().equals(mchntOrderInfoRefund.getMchntNo())).collect(Collectors.toList());
            /*累计退款金额*/
            MchntOrderInfo mchntOrderInfo = mchntOrderInfos.get(0);
            mchntOrderInfo.setRefundAmt(AmountUtil.addition(mchntOrderInfo.getRefundAmt(), mchntOrderInfoRefund.getOrderAmt()));
            mchntOrderInfo.setRefundFee(AmountUtil.addition(mchntOrderInfo.getRefundFee(), mchntOrderInfoRefund.getMchntFee()));
            mchntOrderInfo.setRealRefundFee(AmountUtil.addition(mchntOrderInfo.getRealRefundFee(), mchntOrderInfoRefund.getMchntFee()));
            mchntOrderInfo.setUpdateTime(DateUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS"));
        }
        /* 将原支付交易信息设置到交易缓存中 */
        GlobalTransUtil.setCacheValue(TransCacheConstant.ORIG_USER_ORDER_INFO, origUserOrderInfo);
        GlobalTransUtil.setCacheValue(TransCacheConstant.ORIG_MCHNT_ORDER_INFO_LIST, origMchntOrderInfoList);
        GlobalTransUtil.setCacheValue(TransCacheConstant.ORIG_PAY_ORDER_INFO_LIST, origPayOrderInfoList);
    }

    /**
     * 累加退款金额
     *
     * @param opmsMchntOrderInfos 用户订单信息
     * @return 退金额总金额
     */
    private String countRefundAmt(List<MchntOrderInfo> opmsMchntOrderInfos) {
        String totleRefundAmt = "0";
        for (MchntOrderInfo opmsMchntOrderInfo : opmsMchntOrderInfos) {
            if (!StringUtil.isEmptyOrNull(opmsMchntOrderInfo.getRefundAmt())) {
                totleRefundAmt = AmountUtil.addition(totleRefundAmt, opmsMchntOrderInfo.getRefundAmt());
            }
        }
        return totleRefundAmt;
    }

    /**
     * 获取用户名称
     *
     * @param payOrderStatusQueryRequest 请求体
     * @return 用户名称
     * @throws Exception 异常
     */
    private String getUserName(PayOrderStatusQueryRequest payOrderStatusQueryRequest, String userId) throws Exception {
        String sessionId = payOrderStatusQueryRequest.getHeader().getSession();
        String instId = payOrderStatusQueryRequest.getHeader().getInstId();
        UserService userService = new UserServiceImpl();
        UserInfo userInfo = userService.getUserInfo(instId, userId, sessionId);
        if (null == userInfo) {
            rglog.error("用户不存在或用户已经注销");
            return "";
        }
        return userInfo.getUserName();
    }

    @Override
    public ChannelCallCfg channelCallSceneDiscern(Object request, List<ChannelCallCfg> channelCallCfgList) throws Exception {
        String mixPayFlag = (String) GlobalTransUtil.getCacheValue(TransCacheConstant.MIX_PAY_FLAG);
        PayOrderInfo payOrderInfo = (PayOrderInfo) GlobalTransUtil.getCacheValue(TransCacheConstant.PAY_ORDER_INFO);
        if (null == payOrderInfo) {
            return null;
        }
        String bizScene = getBizSceneCode(payOrderInfo, mixPayFlag);
        List<ChannelCallCfg> channelCallCfgs = channelCallCfgList.stream().filter(item -> item.getBizScene().equals(bizScene)).collect(Collectors.toList());
        if (channelCallCfgs.size() > 1) {
            return getChannelCallCfg(channelCallCfgs);
        } else {
            return channelCallCfgs.stream().findFirst().orElse(null);
        }
    }

    @Override
    public CheckResultEnum channelCallPreCheck(Object request, ChannelCallCfg channelCallCfg, OrderInfo orderInfo) throws Exception {
        String orderPayFlag = (String) GlobalTransUtil.getCacheValue(TransCacheConstant.ORDER_PAY_FLAG);
        if (!StringUtil.isEmptyOrNull(orderPayFlag) && AppParamConstant.NO.equals(orderPayFlag)){
            return CheckResultEnum.FINISH;
        }else {
            return CheckResultEnum.PASSED;
        }
    }

    @Override
    public TransStatusEnum channelCallResultProc(Object request, ChannelCallCfg channelCallCfg, TransStatusEnum transStatusEnum, Object channelResponse, OrderInfo needUpdateOrderInfo) throws Exception {
        if (null != needUpdateOrderInfo && null != needUpdateOrderInfo.getUserOrderInfo()) {
            if (TransTypeEnum.REFUND.equals(TransTypeEnum.getTransType(needUpdateOrderInfo.getUserOrderInfo().getTxnNum()))) {
                /* 获取退款原交易订单信息*/
                OrderService orderService = new OrderServiceImpl();
                UserOrderInfo origUserOrderInfo = (UserOrderInfo) GlobalTransUtil.getCacheValue(TransCacheConstant.ORIG_USER_ORDER_INFO);
                List<MchntOrderInfo> origMchntOrderInfo = (List<MchntOrderInfo>) GlobalTransUtil.getCacheValue(TransCacheConstant.ORIG_MCHNT_ORDER_INFO_LIST);
                List<PayOrderInfo> origPayOrderInfo = (List<PayOrderInfo>) GlobalTransUtil.getCacheValue(TransCacheConstant.ORIG_PAY_ORDER_INFO_LIST);
                if (null != origMchntOrderInfo && !origMchntOrderInfo.isEmpty()) {
                    /* 对原支付交易的商户订单进行状态修改 */
                    for (MchntOrderInfo mchntOrderInfo : origMchntOrderInfo) {
                        if (AmountUtil.compare(mchntOrderInfo.getRealSettleAmt(), mchntOrderInfo.getRefundAmt()) == 0) {
                            if (BizStatusEnum.NOT_CONFIRM_PART_REFUND.getStatus().equals(mchntOrderInfo.getBizStatus()) ||
                                    ("01".equals(mchntOrderInfo.getBizSceneType()) && BizStatusEnum.FINISH.getStatus().equals(mchntOrderInfo.getBizStatus()))) {
                                /* 担保订单未确认收货 */
                                mchntOrderInfo.setBizStatus(BizStatusEnum.NOT_CONFIRM_REFUND.getStatus());
                            } else {
                                mchntOrderInfo.setBizStatus(BizStatusEnum.REFUND.getStatus());
                            }
                        } else {
                            if (BizStatusEnum.NOT_CONFIRM_PART_REFUND.getStatus().equals(mchntOrderInfo.getBizStatus()) ||
                                    ("01".equals(mchntOrderInfo.getBizSceneType()) && BizStatusEnum.FINISH.getStatus().equals(mchntOrderInfo.getBizStatus()))) {
                                mchntOrderInfo.setBizStatus(BizStatusEnum.NOT_CONFIRM_PART_REFUND.getStatus());
                            } else {
                                mchntOrderInfo.setBizStatus(BizStatusEnum.PART_REFUND.getStatus());
                            }
                        }
                        mchntOrderInfo.setUpdateTime(DateUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS"));
                    }
                }
                Predicate<PayOrderInfo> channelFilter = p -> channelCallCfg.getCallChannelId().equals(p.getMsgDstId());
                List<PayOrderInfo> origPayOrderInfoList = Objects.requireNonNull(origPayOrderInfo).stream().filter(channelFilter).collect(Collectors.toList());
                if (!origPayOrderInfoList.isEmpty()) {
                    origPayOrderInfoList.get(0).setBizStatus(Objects.requireNonNull(origMchntOrderInfo).get(0).getBizStatus());
                    if (!orderService.updateOrderStatus(origUserOrderInfo, origMchntOrderInfo, origPayOrderInfoList.get(0))) {
                        rglog.error("更新退款交易原支付订单状态失败:{}", JSON.toJSONString(origUserOrderInfo));
                    }
                }
            }
        }
        return transStatusEnum;
    }

    /**
     * 根据业务场景及通道配置，以及业务逻辑返回唯一的通道调用配置
     *
     * @param channelCallCfgList 业务场景对应的通道配置信息
     * @return 通道调用配置
     */
    private ChannelCallCfg getChannelCallCfg(List<ChannelCallCfg> channelCallCfgList) {
        Optional<ChannelCallCfg> channelCallCfgOpt;
        if ("0101".equals(channelCallCfgList.get(0).getCallIndex()) || "0102".equals(channelCallCfgList.get(0).getCallIndex())) {
            List<MchntOrderInfo> mchntOrderInfoList = (List<MchntOrderInfo>) GlobalTransUtil.getCacheValue(TransCacheConstant.MCHNT_ORDER_INFO_LIST);
            if ("00".equals(Objects.requireNonNull(mchntOrderInfoList).get(0).getBizSceneType()) || "01".equals(mchntOrderInfoList.get(0).getBizSceneType())
                    || "02".equals(mchntOrderInfoList.get(0).getBizSceneType()) || "0".equals(mchntOrderInfoList.get(0).getFeeInputMode())) {
                /* 担保支付、购买卡卷、特殊计算商户不给商户进行实时入账及虚拟账记账，只推送交易结果通知 */
                rglog.info("订单全为购买卡券或担保支付或特殊计费商户的交易，不给商户入账，直接推送通知");
                channelCallCfgOpt = channelCallCfgList.stream().filter(item -> item.getCallChannelId().equals("LOCAL")).findFirst();
            } else {
                if (AppParamConstant.YES.equals(Objects.requireNonNull(mchntOrderInfoList).get(0).getRealSettleFlag())) {
                    /* 商户D0清算场景 */
                    channelCallCfgOpt = channelCallCfgList.stream().filter(item -> item.getCallChannelId().equals(ChannelEnum.ESB.getChannelType())).findFirst();
                } else {
                    /* 商户非D0清算场景 */
                    channelCallCfgOpt = channelCallCfgList.stream().filter(item -> item.getCallChannelId().equals(ChannelEnum.ACCT.getChannelType())).findFirst();
                }
            }
            return channelCallCfgOpt.orElse(null);
        }
        return null;
    }

    /**
     * 根据支付方式获取业务场景
     *
     * @param payOrderInfo 支付订单信息
     * @param mixPayFlag   混合支付标志
     * @return 业务场景
     */
    private String getBizSceneCode(PayOrderInfo payOrderInfo, String mixPayFlag) {
        if (PayTypeEnum.WECHAT.getPayType().equals(payOrderInfo.getPayType())) {
            if (TransTypeEnum.PAY.equals(TransTypeEnum.getTransType(payOrderInfo.getTxnNum()))) {
                /* 微信支付状态查询场景 */
                return "00";
            } else if (TransTypeEnum.REFUND.equals(TransTypeEnum.getTransType(payOrderInfo.getTxnNum()))) {
                /* 微信退款状态查询场景 */
                return "01";
            }
        } else if (PayTypeEnum.ALIPAY.getPayType().equals(payOrderInfo.getPayType())) {
            if (TransTypeEnum.PAY.equals(TransTypeEnum.getTransType(payOrderInfo.getTxnNum()))) {
                /* 支付宝支付状态查询场景 */
                return "02";
            } else if (TransTypeEnum.REFUND.equals(TransTypeEnum.getTransType(payOrderInfo.getTxnNum()))) {
                /* 支付宝退款状态查询场景 */
                return "03";
            }
        } else if (PayTypeEnum.CUPS_CLOUD.getPayType().equals(payOrderInfo.getPayType())) {
            if (ChannelEnum.UPQC.getChannelType().equals(payOrderInfo.getMsgDstId()) && "0310000903".equals(payOrderInfo.getDstTxnNum())) {
                if (TransTypeEnum.PAY.equals(TransTypeEnum.getTransType(payOrderInfo.getTxnNum()))) {
                    /* 银联二维码被扫支付状态查询场景 */
                    return "04";
                } else if (TransTypeEnum.REFUND.equals(TransTypeEnum.getTransType(payOrderInfo.getTxnNum()))) {
                    /* 银联二维码被扫退款状态查询场景 */
                    return "05";
                }
            } else if (ChannelEnum.UPQC.getChannelType().equals(payOrderInfo.getMsgDstId())) {
                if (TransTypeEnum.PAY.equals(TransTypeEnum.getTransType(payOrderInfo.getTxnNum()))) {
                    /* 银联二维码主扫支付状态查询场景 */
                    return "06";
                } else if (TransTypeEnum.REFUND.equals(TransTypeEnum.getTransType(payOrderInfo.getTxnNum()))) {
                    /* 银联二维码主扫退款状态查询场景 */
                    return "07";
                }
            } else if (ChannelEnum.UPAC.getChannelType().equals(payOrderInfo.getMsgDstId())) {
                if (TransTypeEnum.PAY.equals(TransTypeEnum.getTransType(payOrderInfo.getTxnNum()))) {
                    /* 银联云闪付支付状态查询场景 */
                    return "08";
                } else if (TransTypeEnum.REFUND.equals(TransTypeEnum.getTransType(payOrderInfo.getTxnNum()))) {
                    /* 银联云闪付退款状态查询场景 */
                    return "09";
                }
            }
        } else if (PayTypeEnum.BANK_CARD.getPayType().equals(payOrderInfo.getPayType())) {
            if (AcctTypeEnum.BANK_CREDIT.getAcctType().equals(payOrderInfo.getPayerAcctType())) {
                if (TransTypeEnum.PAY.equals(TransTypeEnum.getTransType(payOrderInfo.getTxnNum()))) {
                    /* 10:本行贷记卡+积分支付状态查询场景,14-本行贷记卡支付状态查询场景 */
                    return AppParamConstant.YES.equals(mixPayFlag) ? "10" : "14";
                } else if (TransTypeEnum.REFUND.equals(TransTypeEnum.getTransType(payOrderInfo.getTxnNum()))) {
                    /* 11-本行贷记卡+积分退款状态查询场景,15-本行贷记卡退款状态查询场景 */
                    return AppParamConstant.YES.equals(mixPayFlag) ? "11" : "15";
                }
            } else if (AcctTypeEnum.BANK_DEBIT.getAcctType().equals(payOrderInfo.getPayerAcctType())) {
                if (TransTypeEnum.PAY.equals(TransTypeEnum.getTransType(payOrderInfo.getTxnNum()))) {
                    /* 12-本行借记卡+积分支付状态查询场景,16-本行借记卡支付状态查询场景 */
                    return AppParamConstant.YES.equals(mixPayFlag) ? "12" : "16";
                } else if (TransTypeEnum.REFUND.equals(TransTypeEnum.getTransType(payOrderInfo.getTxnNum()))) {
                    /* 13-本行借记卡+积分退款状态查询场景,17-本行借记卡退款状态查询场景 */
                    return AppParamConstant.YES.equals(mixPayFlag) ? "13" : "17";
                }
            } else if (ShareParamConstant.BSPS_CASH_TXN_NUM.equals(payOrderInfo.getTxnNum())) {
                /* 本行卡虚拟账户提现状态查询场景 */
                return "32";
            } else if (ShareParamConstant.BSPS_ACCT_RECHARGE_TXN_NUM.equals(payOrderInfo.getTxnNum())) {
                /* 虚拟账户充值状态查询场景 */
                return "34";
            }
        } else if (PayTypeEnum.OTHER_BANK_CARD.getPayType().equals(payOrderInfo.getPayType())) {
            if (!StringUtil.isEmptyOrNull(payOrderInfo.getDstChannelType()) && payOrderInfo.getDstChannelType().startsWith("TK")) {
                if (TransTypeEnum.PAY.equals(TransTypeEnum.getTransType(payOrderInfo.getTxnNum()))) {
                    /* 银联无跳转支付状态查询场景 */
                    return "18";
                } else if (TransTypeEnum.REFUND.equals(TransTypeEnum.getTransType(payOrderInfo.getTxnNum()))) {
                    /* 银联无跳转退款状态查询场景 */
                    return "19";
                }
            } else if (!StringUtil.isEmptyOrNull(payOrderInfo.getDstChannelType()) && payOrderInfo.getDstChannelType().equals(ChannelEnum.NCQS.getChannelType())) {
                if (TransTypeEnum.PAY.equals(TransTypeEnum.getTransType(payOrderInfo.getTxnNum()))) {
                    /* 银联无卡快捷支付状态查询场景 */
                    return "20";
                } else if (TransTypeEnum.REFUND.equals(TransTypeEnum.getTransType(payOrderInfo.getTxnNum()))) {
                    /* 银联无卡快捷退款状态查询场景 */
                    return "21";
                }
            } else if (!StringUtil.isEmptyOrNull(payOrderInfo.getDstChannelType()) && payOrderInfo.getDstChannelType().equals(ChannelEnum.UPGW.getChannelType())) {
                if (TransTypeEnum.PAY.equals(TransTypeEnum.getTransType(payOrderInfo.getTxnNum()))) {
                    /* 22-银联新个人网银支付状态查询场景,24-银联新企业网银支付状态查询场景 */
                    return "00".equals(payOrderInfo.getBizType()) ? "22" : "24";
                } else if (TransTypeEnum.REFUND.equals(TransTypeEnum.getTransType(payOrderInfo.getTxnNum()))) {
                    /* 23-银联新个人网银退款状态查询场景,25-银联新企业网银退款状态查询场景 */
                    return "01".equals(payOrderInfo.getBizType()) ? "23" : "25";
                }
            } else if (!StringUtil.isEmptyOrNull(payOrderInfo.getDstChannelType()) && payOrderInfo.getDstChannelType().startsWith("GW")) {
                if (TransTypeEnum.PAY.equals(TransTypeEnum.getTransType(payOrderInfo.getTxnNum()))) {
                    /* 个人网关支付状态查询场景 */
                    return "26";
                } else if (TransTypeEnum.REFUND.equals(TransTypeEnum.getTransType(payOrderInfo.getTxnNum()))) {
                    /* 个人网关退款状态查询场景 */
                    return "27";
                }
            } else if (!StringUtil.isEmptyOrNull(payOrderInfo.getDstChannelType()) && payOrderInfo.getDstChannelType().startsWith("BB")) {
                if (TransTypeEnum.PAY.equals(TransTypeEnum.getTransType(payOrderInfo.getTxnNum()))) {
                    /* 企业网关支付状态查询场景 */
                    return "28";
                } else if (TransTypeEnum.REFUND.equals(TransTypeEnum.getTransType(payOrderInfo.getTxnNum()))) {
                    /* 企业网关退款状态查询场景 */
                    return "29";
                }
            } else if (ChannelEnum.CPCN.getChannelType().equals(payOrderInfo.getMsgDstId())) {
                if (TransTypeEnum.PAY.equals(TransTypeEnum.getTransType(payOrderInfo.getTxnNum()))) {
                    /* 中金网关支付状态查询场景 */
                    return "30";
                } else if (TransTypeEnum.REFUND.equals(TransTypeEnum.getTransType(payOrderInfo.getTxnNum()))) {
                    /* 中金网关退款状态查询场景 */
                    return "31";
                }
            } else if (ShareParamConstant.BSPS_CASH_TXN_NUM.equals(payOrderInfo.getTxnNum())) {
                /* 他行卡虚拟账户提现状态查询场景 */
                return "33";
            }
        }
        rglog.error("暂时不支持的业务场景!");
        return null;
    }
}
